<template>
  <div class="search-box">
    <!-- 头 -->
    <div class="searchPage-title">
      <Head />
      <div class="searchPage-icon" @click="gotoHome">
        <van-icon name="arrow-left" size="0.5rem" />
      </div>
      <div class="searchPage-search" @click="gotoSearchTwo"><SearchInput /></div>
    </div>

    <!-- 下边 -->
    <div class="search-info">
      <p>热门搜索</p>
      <ul class="search-list">
        <li class="search-name" v-for="item in hotSearchList" :key="item.id">
          <span> {{ item.city }} </span>
        </li>
        <div style="clear: both"></div>
      </ul>
    </div>

    <!-- 历史记录 -->
    <div class="search-history">
      <p>历史记录</p>
      <ul v-if="history">
        <li>
          大叔动哈死的活该啊实打实大苏打实打实大苏打实打实阿三大苏打实打实大苏打实打实的i法国哈雕塑覅
        </li>
        <li>
          大叔动哈死的活该啊实打实大苏打实打实大苏打实打实阿三大苏打实打实大苏打实打实的i法国哈雕塑覅
        </li>
        <li>
          大叔动哈死的活该啊实打实大苏打实打实大苏打实打实阿三大苏打实打实大苏打实打实的i法国哈雕塑覅
        </li>
        <li>
          大叔动哈死的活该啊实打实大苏打实打实大苏打实打实阿三大苏打实打实大苏打实打实的i法国哈雕塑覅
        </li>
        <li>
          大叔动哈死的活该啊实打实大苏打实打实大苏打实打实阿三大苏打实打实大苏打实打实的i法国哈雕塑覅
        </li>
        <li>
          大叔动哈死的活该啊实打实大苏打实打实大苏打实打实阿三大苏打实打实大苏打实打实的i法国哈雕塑覅
        </li>
      </ul>
      <button @click="clearHistory">清空历史记录</button>
    </div>
  </div>
</template>

<script>
import Head from "../../../components/head/Head";
import SearchInput from "../../../components/searchInput/SearchInput";
import api from "../../../api";

export default {
  name: "SearchPage",
  data() {
    return {
      //   iconName: "arrow-left",
      hotSearchList: [],
      history: true,
    };
  },
  components: {
    SearchInput,
    Head,
  },
  mounted() {
    api.gotoHotSearch().then((res) => {
      //   console.log(res.data);
      this.hotSearchList = res.data.list;
    });
  },
  methods: {
    gotoHome() {
      this.$router.push("/");
    },
    clearHistory() {
      this.$dialog
        .confirm({
          title: "是否删除历史记录",
          confirmButtonColor: "red",
        })
        .then(() => {
          this.history = false;
        })
        .catch(() => {
          console.log("点击了取消");
        });
    },
    gotoSearchTwo() {
      console.log(1);
      this.$router.push("/searchPageTwo");
    },
  },
};
</script>

<style lang="less">
.searchPage-title {
  width: 100%;
  position: relative;
  .searchPage-search {
    width: 80%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
  .searchPage-icon {
    height: 0.5rem;
    position: absolute;
    bottom: 0;
    top: 0;
    margin: auto 0;
  }
}
.search-info {
  width: 90%;
  margin: 0 auto;
  padding-bottom: 0.5rem;
  box-shadow: 0px 0px 0.1rem #ccc;
  p {
    text-align: left;
    font-size: 20px;
    font-weight: 900;
    margin-top: 0.3rem;
    padding: 0.3rem 0 0 0.4rem;
    color: rgba(000, 000, 000, 0.7);
  }
  .search-name {
    float: left;
    width: 25%;
    text-align: center;
    margin-top: 0.35rem;
    span {
      display: block;
      margin: 0 auto;
      width: 80%;
      font-size: 13px;
      border-radius: 0.08rem;
      padding: 0.12rem 0;
      background-color: rgba(000, 000, 000, 0.1);
    }
  }
}

.search-history {
  width: 90%;
  margin: 0 auto;
  overflow: hidden;
  p {
    text-align: left;
    font-size: 20px;
    font-weight: 700;
    margin-top: 0.3rem;
    padding: 0.3rem 0 0 0.4rem;
    color: rgba(000, 000, 000, 0.7);
  }
  ul {
    margin-top: 0.35rem;
    li {
      width: 100%;
      height: 0.6rem;
      color: rgba(000, 000, 000, 0.7);
      line-height: 0.6rem;
      text-align: left;
      padding-left: 0.4rem;
      font-size: 13px;
      border-bottom: 0.01rem solid #ccc;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }

  button {
    display: block;
    margin-top: 0.2rem;
    width: 100%;
    height: 0.8rem;
    line-height: 0.8rem;
  }
}
</style>
>
